package com.kolon.framework.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.kolon.framework.constant.Constant;


/**
 * 관리자 세션 체크 인터셉터
 * @author stone
 *
 */
public class MngrInterceptor extends HandlerInterceptorAdapter {
	
	/**
	 * 컨트롤러 실행 전 호출되는 인터셉터 함수
	 */
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 
			Object handler) throws Exception {
		HttpSession httpSession = request.getSession();
		// 관리자 세션 체크
		if (httpSession == null || httpSession.getAttribute(Constant.SESSION_MNGR_INFO) == null) {
			httpSession.invalidate();
			if (request.getParameter("pop") == null)
				response.sendRedirect(request.getContextPath() + "/business/mngr/index.do");
			else
				response.sendRedirect(request.getContextPath() + "/business/mngr/index.do?pop=Y");
			return false;
		}
		return true;
	}

}
